package reflex;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Arrays;

@Deprecated
public class Reflex {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
        //获取class对象
        Class clazz1 = Class.forName("reflex.Student");
        System.out.println(clazz1);
        Class clazz2 = Student.class;
        System.out.println(clazz2);
        Student student = new Student();
        Class clazz3 = student.getClass();
        System.out.println(clazz3);
        System.out.println(clazz1 == clazz2);
        System.out.println(clazz1 == clazz3);
        System.out.println("====================");
        //获取成员变量
        //获取public修饰的成员变量
        Field[] fields = clazz2.getFields();
        System.out.println(Arrays.toString(fields));
        //获取单个public修饰的成员变量
        Field a = clazz3.getField("a");
        System.out.println(a);
        //设置成员变量的值
        Student student1 = new Student();
        a.set(student1, 23);
        System.out.println(student1);
        //获取所有成员变量
        Field[] declaredFields = clazz3.getDeclaredFields();
        String string = Arrays.toString(declaredFields);
        System.out.println(string);
        //获取指定成员变量
        Field a1 = clazz3.getDeclaredField("a");
        Object o = a.get(student1);
        System.out.println(o);
        //获取成员方法
        //获取构造方法
        Constructor[] constructors = clazz3.getConstructors();
    }
}
